package com.swufe.lianxi;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

public class RateCalcActivity extends AppCompatActivity {
String TAG="ratecalc";
float rate=0f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_calc);
        String title=getIntent().getStringExtra("title");
        Log.i(TAG, "onCreate: ..."+title);
        rate=getIntent().getFloatExtra("rate",0.0f);
        Log.i(TAG, "onCreate: title="+title);
        Log.i(TAG, "onCreate: rate="+rate);
        TextView title1=findViewById(R.id.title1);
        title1.setText(""+title);//注意与title1.setText("title");区别
        EditText inp2=(EditText) findViewById(R.id.inp2);
        inp2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
            TextView show=(TextView) RateCalcActivity.this.findViewById(R.id.show2);
            String s = inp2.getText().toString();
            if(s.length()>0){
                
                float val=Float.parseFloat(s);
                show.setText(val+"RMB=="+(100/rate*val));
            }else{
                show.setText("");
            }
        }

        });

    }
}